import IM from '@/im'

const { Contact } = IM

const getters = {
  getDictMap: (state) => state.dict.dictMap,
  getIsSetDict: (state) => state.dict.isSetDict,
  token: (state) => state.user.accessToken,
  studentId: (state) => state.user.userId,
  contacts: (state) => {
    const { conversations, boundPersons } = state.im

    return boundPersons.map((person) => {
      const conversation = conversations[person.userImId]

      if (!conversation) {
        return new Contact({
          targetId: person.userImId,
          unreadCount: 0,
          messages: []
        })
      } else {
        return new Contact(conversation)
      }
    })
  }
}

export default getters
